package com.zq.多线程设计模式.workerThread设计模式;

import java.util.Random;
import java.util.concurrent.TimeUnit;

public class Worker extends Thread {


    private final ProductionChannel productionChannel;

    private final static Random random = new Random(System.currentTimeMillis());

    public Worker(String workerName, ProductionChannel productionChannel) {
        super(workerName);
        this.productionChannel = productionChannel;
    }

    @Override
    public void run() {
        while (true){
            try {
                Production production = productionChannel.takeProduction();
                System.out.println(getName() + " process the " + production);
                production.creat();
                TimeUnit.SECONDS.sleep(random.nextInt(10));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
